/*****************************
*   brA Convert TXT to SQL
*   Autor: Shiraz
*	Data: 22/10/2012
******************************/

#ifndef	_BRA_CONVERT_H_
#define	_BRA_CONVERT_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <mysql/mysql.h>

// Macros

#define TXTCOLOR(x) (SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x))
#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))
#define DIR(x) (x == 1 ? "db":"data")

#define TBUFFER 0x80   // ~ 128
#define LBUFFER 0x100  // ~ 256
#define MBUFFER 0x200  // ~ 512
#define HBUFFER 0x400  // ~ 1024
#define SBUFFER 0x8000 // ~ 32768

#define YEAR "2013"
#define CONFIG_FILE "CONFIG.INI"
#define NEWLINE "\n"

struct configuration {
	char host[MBUFFER], user[MBUFFER], password[MBUFFER], database[MBUFFER], version[MBUFFER];
};

struct database {
	char item_name[MBUFFER], skill_name[MBUFFER], mob_name[MBUFFER];
	int item_id, skill_id, mob_id;
};

enum txt_colors {
	DEFAULT = 15,
	GREEN = 47,
	YELLOW = 14,
	RED = 12,
	PINK = 13,
	WHITE = 7,
	LIGHT_GREEN = 10
};

struct configuration config;
static struct database item_data[SBUFFER], mob_data[SBUFFER], skill_data[SBUFFER];

static unsigned int file_count;

MYSQL *mysqlPtr;

void init_system(void);
void abort_system(void);
void show_message(int color, const char *msg, ...);

int exec_mysql_query(const char* query);

void convert_abra_db();
void convert_castle_db();
void convert_create_arrow_db();
void convert_elemental_db();
void convert_elemental_skill_db();
void convert_guild_skill_tree_db();
void convert_homunculus_db();
void convert_homun_skill_tree_db();
void convert_item_avail_db();
void convert_item_delay_db();
void convert_item_findingore_db();
void convert_item_stack_db();
void convert_magicmushroom_db();
void convert_mercenary_db();
void convert_mercenary_skill_db();
void convert_mob_avail_db();
void convert_mob_chat_db();
void convert_mob_classchange_db();
void convert_mob_item_ratio_db();
void convert_mob_pouch_db();
void convert_pet_db();
void convert_produce_db();
void convert_skill_changematerial_db();
void convert_skill_improvise_db();
void convert_skill_reproduce_db();
void convert_spellbook_db();
void convert_quest_db();
void convert_size_fix_db();
void convert_item_bluebox_db();
void convert_item_buyingstore_db();
void convert_item_cardalbum_db();
void convert_item_combo_db();
void convert_item_giftbox_db();
void convert_item_misc_db();
void convert_item_noequip_db();
void convert_item_trade_db();
void convert_item_violetbox_db();
void convert_mob_boss_db();
void convert_mob_branch_db();
void convert_mob_poring_db();
void convert_mob_race2_db();
void convert_skill_cast_db();
void convert_skill_castnodex_db();
void convert_skill_db();
void convert_skill_nocast_db();
void convert_skill_require_db();
void convert_skill_tree_db();
void convert_skill_unit_db();
void convert_exp_guild_db();
void convert_exp_homun_db();
void convert_statpoint_db();
void convert_refine_db();
void convert_mob_db();
void convert_mob_skill_db();
void convert_item_db();

int explode(char ***arr_ptr, char *str, char delimiter);
void file_dat(char str[], int key);
int count_char(char *str, char c);
char *replace_str(char *str, char *orig, char *rep);
char *escape_str(char *str);

const char *getitemname(int item_id, char *item_name);
const char *getskillname(int skill_id, char *skill_name);
const char *getmobname(int mob_id, char *mob_name);

#endif
